package com.wyg.blog.controller.user;

import com.wyg.blog.model.user.Role;
import com.wyg.blog.service.user.RoleService;
import com.wyg.blog.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description:
 * @author: WYG
 * @time: 2020/6/29 20:19
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    RoleService roleService;

    @PostMapping("addRole")
    @CrossOrigin
    @PreAuthorize("hasRole('SUPER_ADMIN')")
    public JsonResult<Integer> addRole(Map<String,String> roleInfo){
        Role role = new Role();
        role.setId(0);
        role.setRole_name(roleInfo.get("name"));
        role.setRole_description(roleInfo.get("description"));
        boolean res = roleService.insertRole(role);
        if(res) {
            return new JsonResult<>(1,"200","添加成功");
        } else {
            return new JsonResult<>(1,"701","添加失败");
        }
    }

}
